//
//  ContainerView.swift
//  LearnSemanticContentAttribute
//
//  Created by NMXY_IOS on 2020/12/29.
//

import UIKit

class ContainerView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.overrideUserInterfaceStyle = .light
        createUI()
        
        if UIView.userInterfaceLayoutDirection(for: self.semanticContentAttribute) == .rightToLeft {
            print("rightToLeft")
        }else{
            print("LeftToRight")
        }
        
        if UIView.userInterfaceLayoutDirection(for: self.semanticContentAttribute, relativeTo: self.effectiveUserInterfaceLayoutDirection) == .rightToLeft {
            print("rightToLeft")
        }else{
            print("LeftToRight")
        }
        
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func createUI(){
        self.translatesAutoresizingMaskIntoConstraints = false
        
        self.addSubview(self.label)
        self.addSubview(self.textfiled)
        self.addSubview(self.button)
        
        NSLayoutConstraint.activate([
            
            self.label.leadingAnchor.constraint(equalTo: self.layoutMarginsGuide.leadingAnchor),
            self.label.topAnchor.constraint(equalTo: self.layoutMarginsGuide.topAnchor),

            self.textfiled.leadingAnchor.constraint(equalTo: self.label.trailingAnchor, constant: 10),
            self.textfiled.topAnchor.constraint(equalTo: self.layoutMarginsGuide.topAnchor),
            self.textfiled.trailingAnchor.constraint(equalTo: self.layoutMarginsGuide.trailingAnchor),
            
            self.button.topAnchor.constraint(equalTo: self.textfiled.bottomAnchor, constant: 10),
            self.button.centerXAnchor.constraint(equalTo: self.centerXAnchor),
            self.button.heightAnchor.constraint(equalToConstant: 30)
        
        ])
    }
    
    
    private lazy var label: UILabel = {
        let tempLabel = UILabel()
        tempLabel.numberOfLines = 0
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.text = "姓名"
        tempLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 999), for: .horizontal)
        tempLabel.backgroundColor = UIColor.cyan
        return tempLabel
    }()
    
    private lazy var textfiled:UITextField = {
        let tempTextField = UITextField ()
        tempTextField.placeholder = "输入你的名字"
        tempTextField.backgroundColor = UIColor.orange
        tempTextField.translatesAutoresizingMaskIntoConstraints = false
        return tempTextField
    }()
    
    private lazy var button : UIButton = {
        let tempButton: UIButton = UIButton (type: .custom)
        tempButton.setTitle("Login", for: .normal)
        tempButton.setImage(UIImage (named: "point"), for: .normal)
        tempButton.backgroundColor = UIColor.white
        tempButton.setTitleColor(UIColor.red, for: .normal)
        tempButton.translatesAutoresizingMaskIntoConstraints = false
        tempButton.imageView?.setContentHuggingPriority(UILayoutPriority(rawValue: 200), for: .horizontal)
        tempButton.imageView?.setContentHuggingPriority(UILayoutPriority(rawValue: 200), for: .vertical)
        tempButton.imageView?.contentMode = .scaleAspectFit
        tempButton.layer.borderWidth = 0.5
        tempButton.layer.borderColor = UIColor.black.cgColor
        return tempButton
    }()
    

}
